from rest_framework.serializers import ModelSerializer
from message import models


class CategorySerializer(ModelSerializer):
    class Meta:
        model = models.Cate
        fields = '__all__'


class MessageSerializer(ModelSerializer):
    cate_info = CategorySerializer(source='cate', read_only=True)

    class Meta:
        model = models.Message
        fields = [
            'id',
            'title',
            'content',
            'publisher',
            'status',
            'cate',
            'created_at',
            'cate_info'
        ]

    def get_cate_info(self, obj):
        return obj.cate.name
